package cn.chenxing.module.login.utils;

import cn.chenxing.constant.VenusConstant;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.input.ClassLoaderObjectInputStream;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import java.io.InputStream;
import java.util.Properties;

/**
 * @Description 是否需要登录
 * @Author maogen.ymg
 * @Date 2020/2/24 20:53
 */
@PropertySource({"classpath:/application.yaml"})
@Component
@Slf4j
public class IsLoginUtil {

    private IsLoginUtil() {}

    public static boolean getProperties() {
        Properties prop = new Properties();
        String value;
        boolean flag = true;
        // 通过输入缓冲流进行读取配置文件
        try (InputStream in = ClassLoaderObjectInputStream.class.getResourceAsStream("/application.yaml")){
            // 加载输入流
            prop.load(in);
            value = prop.getProperty(VenusConstant.NEED_LOGIN);
            flag = !value.equals(String.valueOf(Boolean.FALSE));

        } catch (Exception e) {
            log.error("检测是否登录错误{}", e.getMessage(), e);
        }
        return flag;
    }
}
